import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import axios from 'axios'

// 导入小图标
import './assets/fonts/iconfont.css'
// 全局样式
import './assets/css/global.css'

// 导入elementUi
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'

// 导入加载显示插件
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

// 导入树形控件组件https://github.com/MisterTaki/vue-table-with-tree-grid
import ZkTable from 'vue-table-with-tree-grid'

// 配置请求的根路径
axios.defaults.baseURL = 'http://127.0.0.1:8888/api/private/v1/'
Vue.prototype.$http = axios

// 添加请求拦截器
axios.interceptors.request.use(function (config) {
  NProgress.start()
  // 给请求头Authorization字段带token值
  config.headers.Authorization = sessionStorage.getItem('token')
  return config
})

// 添加响应拦截器
axios.interceptors.response.use(function (response) {
  if (response.data.meta.status !== 200) {
    // alert(response.data.meta.msg)
  }
  NProgress.done()
  return response
})

Vue.use(ElementUI)
Vue.use(NProgress) // 安装加载显示插件
Vue.component('tree-table', ZkTable) // 注册树形网格全局组件

Vue.config.productionTip = false

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
